package org.jeecg.modules.htxincailiao.enterprise.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.modules.htxincailiao.account.domain.dto.HTAccountAuthDTO;
import org.jeecg.modules.htxincailiao.account.entity.HTPlatformUser;
import org.jeecg.modules.htxincailiao.address.domain.vo.HTAddressVO;
import org.jeecg.modules.htxincailiao.address.entity.HTEnterpriseAddress;
import org.jeecg.modules.htxincailiao.address.service.IHTEnterpriseAddressService;
import org.jeecg.modules.htxincailiao.enterprise.domain.dto.HTEnterpriseDTO;
import org.jeecg.modules.htxincailiao.enterprise.domain.vo.HTEnterpriseVO;
import org.jeecg.modules.htxincailiao.enterprise.entity.HTBusinessModelCategory;
import org.jeecg.modules.htxincailiao.enterprise.service.IHTBusinessModelCategoryService;
import org.jeecg.modules.htxincailiao.enterprise.service.IHTEnterpriseService;
import org.jeecg.modules.htxincailiao.industry.entity.HTIndustryCategory;
import org.jeecg.modules.htxincailiao.industry.service.IHTIndustryCategoryService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.jeecg.common.util.oConvertUtils;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Objects;

@Api(tags="ht_enterprise")
@RestController
@RequestMapping("/enterprise/")
@Slf4j
public class HTEnterpriseController {

    @Resource
    private IHTEnterpriseService enterpriseService;

    @Resource
    private IHTIndustryCategoryService industryCategoryService;

    @Resource
    private IHTBusinessModelCategoryService businessModelCategoryService;

    @Resource
    private IHTEnterpriseAddressService enterpriseAddressService;

    /**
     * @param request
     * @return
     */
    @PostMapping(value = "getInfoById")
    public Result<HTEnterpriseVO> getInfoById(HttpServletRequest request, @Valid @RequestBody HTEnterpriseDTO dto) {
        Result<HTEnterpriseVO> result = new Result<>();
        HTEnterpriseVO info =  enterpriseService.queryById(dto.getId());
        if (oConvertUtils.isNotEmpty(info)){
            HTIndustryCategory industryCategory = industryCategoryService.getById(info.getIndustryCategoryId());
            HTBusinessModelCategory businessModelCategory = businessModelCategoryService.getById(info.getBusinessModelId());

            HTAddressVO enterpriseAddress = enterpriseAddressService.queryByAddressId(info.getEnterpriseAddressId());
            if (oConvertUtils.isNotEmpty(enterpriseAddress)){
                info.setAddress(enterpriseAddress);
            }
            if (oConvertUtils.isNotEmpty(industryCategory) && oConvertUtils.isNotEmpty(industryCategory.getName())){
                info.setIndustryCategoryName(industryCategory.getName());
            }

            if (oConvertUtils.isNotEmpty(businessModelCategory) && oConvertUtils.isNotEmpty(businessModelCategory.getName())) {
                info.setBusinessModelName(businessModelCategory.getName());
            }
        }

        result.setResult(info);

        return result;
    }




}
